package net.wofly.sale.order.service.impl;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.wofly.right.domain.ReceivingAddr;
import net.wofly.right.service.IReceivingAddrService;
import net.wofly.sale.order.domain.OrderReceivingAddr;
import net.wofly.sale.order.repository.OrderReceivingAddrRepository;
import net.wofly.sale.order.service.IOrderReceivingAddrService;

@Service("iOrderReceivingAddrService")
@Transactional
public class OrderReceivingAddrServiceImpl implements IOrderReceivingAddrService {

	@Autowired
	OrderReceivingAddrRepository orderReceivingAddrRepository;
	@Autowired
	IReceivingAddrService iReceivingAddrService ;
	@Autowired
	IOrderReceivingAddrService iOrderReceivingAddrService ;

	@Override
	public OrderReceivingAddr save(OrderReceivingAddr entity) {
		return orderReceivingAddrRepository.save(entity);
	}

	@Override
	public void delete(OrderReceivingAddr entity) {
		orderReceivingAddrRepository.delete(entity);
	}

	@Override
	public void delete(String key) {
		orderReceivingAddrRepository.delete(key);
	}

	@Override
	public OrderReceivingAddr findOne(String key) {
		return orderReceivingAddrRepository.findOne(key);
	}

	@Override
	public List<OrderReceivingAddr> save(List<OrderReceivingAddr> entityList) {
		return (List<OrderReceivingAddr>) orderReceivingAddrRepository.save(entityList);
	}

	@Override
	public OrderReceivingAddr findByOrderID(String orderID) {
		
		OrderReceivingAddr orderReceivingAddr = orderReceivingAddrRepository.findByOrderID(orderID) ;
        
        if (null!=orderReceivingAddr) {
        		ReceivingAddr receivingAddr = iReceivingAddrService.findOne(orderReceivingAddr.getReceivingAddrID()) ;
        		orderReceivingAddr.setReceivingAddr(receivingAddr);
        }
        
		return orderReceivingAddr ;
	}
}
